<?php
function trimTitle($title){
    $retVal = $title;
    if(strlen($title)>23){
        $retVal = substr($title,0,21) . "...";
    }
    return $retVal;
}

function displayEvents($maxEvents) {
    $CI =& get_instance();
    $CI->load->Model("EventsModel");
    $todayStamp  = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
    $nextStamp  = mktime(0, 0, 0, date("m"), date("d"), date("Y")+1);
    $start = date('Y-m-d H:i:s',$todayStamp);
    $end = date('Y-m-d H:i:s',$nextStamp);
    $listArr = $CI->EventsModel->getEventsList("na",$start,$end,$maxEvents);
    $currMonth = "";
    $lines = 0;
    foreach($listArr as $list){
            if($lines>6)
                break;
            list($year,$month,$day) = explode("-",$list["startDate"]);
            $tmpCurrMonth = date("M",strtotime($list["startDate"]));
            if($currMonth != $tmpCurrMonth) {
                    if($currMonth!="")
                        echo "</ul>";
                    $currMonth = $tmpCurrMonth; // set currMonth
                    echo "<h4>" . $currMonth . "</h4><ul>";
                    $lines++;
                }
                $title = trimTitle($list["title"]);
                echo "<li>" . date("n/j",strtotime($list["startDate"])) . " - " . "<a href=\"/events/view/" . $list["id"] . "\" title=\"" . $list["short_description"] . "\">" . $title . "</a></li>";
                $lines++;
        }
    echo "</ul>";
}
?>